﻿namespace LitBT
{
    /// <summary>
    /// 重复节点
    /// 每帧重复，可指定重复次数
    /// </summary>
    public class RepeatNode : DecoratorNode
    {
        /// <summary>
        /// 重复次数
        /// </summary>
        public int repeatCount;
        /// <summary>
        /// 当前次数
        /// </summary>
        private int currentCount;
        protected override void OnStart()
        {
            currentCount = repeatCount;
        }

        protected override void OnStop()
        {

        }

        protected override State OnUpdate()
        {
            if (currentCount == -1)
            {
                child.Update();
                return State.Running;
            }
            else if (currentCount > 0)
            {
                child.Update();
                currentCount--;
                return State.Running;
            }
            else
            {
                return State.Success;
            }
        }
    }
}